using System;
using System.Globalization;

namespace iPhOwa.Exchange
{
	/// <summary>
	/// Utility for working with dates.
	/// </summary>
	public static class DateExtensions
	{
		/// <summary>
		/// Make a date and time nice for short output.
		/// </summary>
		public static string ToFriendlyShortDateTime(this DateTime date)
		{
			DateTime now = DateTime.Now;

			if(date.Date == now.Date)
			{
				return string.Format(CultureInfo.CurrentUICulture, "Today {0}", date.ToString("%h:mm tt", CultureInfo.CurrentUICulture));
			}

			if(date.Date == now.Date.AddDays(-1))
			{
				return string.Format(CultureInfo.CurrentUICulture, "Yesterday {0}", date.ToString("%h:mm tt", CultureInfo.CurrentUICulture));
			}

			if(date.Year == now.Year)
			{
				return date.ToString("MMM %d %h:mm tt", CultureInfo.CurrentUICulture);
			}

			return date.ToString("MMM %d, yyyy %h:mm tt", CultureInfo.CurrentUICulture);
		}

		/// <summary>
		/// Make date frienldy output.
		/// </summary>
		public static string ToFriendlyLongDate(this DateTime date)
		{
			DateTime now = DateTime.Now.Date;

			if(date.Date == now)
			{
				return string.Format(CultureInfo.CurrentUICulture, "Today, {0}", date.ToString("MMMM dd, yyyy", CultureInfo.CurrentUICulture));
			}

			if(date.Date == now.AddDays(1))
			{
				return string.Format(CultureInfo.CurrentUICulture, "Tomorrow, {0}", date.ToString("MMMM dd, yyyy", CultureInfo.CurrentUICulture));
			}

			return date.ToLongDateString();
		}

		/// <summary>
		/// Make a friendly short date.
		/// </summary>
		public static string ToFriendlyShortDate(this DateTime date)
		{
			DateTime now = DateTime.Now.Date;

			if(date.Date == now)
			{
				return "Today";
			}

			if(date.Date == now.AddDays(1))
			{
				return "Tomorrow";
			}

			return date.ToShortDateString();
		}
	}
}